package com.zyzd.commontools.utils;

import android.text.TextUtils;
import android.util.Log;

@SuppressWarnings("ALL")
public class LogUtils {

    public static boolean DEBUG = true; //调试模式
    private static String TAG = "zyzd";
    private static int LOG_MAXLENGTH = 2000;

    public static final void setTag(String tag) {
        if (TextUtils.isEmpty(tag)) return;
        TAG = tag;
    }

    public static final void setDebug(boolean debug) {
        DEBUG = debug;
    }

    public static final void d(String log) {
        d(TAG, log);
    }

    public static final void d(String tagName, String msg) {
        if (TextUtils.isEmpty(msg))
            return;
        if (DEBUG) {
            int strLength = msg.length();
            int start = 0;
            int end = LOG_MAXLENGTH;
            for (int i = 0; i < 100; i++) {
                if (strLength > end) {
                    Log.d(tagName + i, msg.substring(start, end));
                    start = end;
                    end = end + LOG_MAXLENGTH;
                } else {
                    Log.d(tagName + i, msg.substring(start, strLength));
                    break;
                }
            }
        }
    }

    public static final void e(String log) {
        e(TAG, log);
    }

    public static final void e(String tagName, String msg) {
        if (TextUtils.isEmpty(msg))
            return;
        if (DEBUG) {
            int strLength = msg.length();
            int start = 0;
            int end = LOG_MAXLENGTH;
            for (int i = 0; i < 100; i++) {
                if (strLength > end) {
                    Log.e(tagName + i, msg.substring(start, end));
                    start = end;
                    end = end + LOG_MAXLENGTH;
                } else {
                    Log.e(tagName + i, msg.substring(start, strLength));
                    break;
                }
            }
        }
    }

    public static final void i(String log) {
        i(TAG, log);
    }

    public static final void i(String tagName, String msg) {
        if (TextUtils.isEmpty(msg))
            return;
        if (DEBUG) {
            int strLength = msg.length();
            int start = 0;
            int end = LOG_MAXLENGTH;
            for (int i = 0; i < 100; i++) {
                if (strLength > end) {
                    Log.i(tagName + i, msg.substring(start, end));
                    start = end;
                    end = end + LOG_MAXLENGTH;
                } else {
                    Log.i(tagName + i, msg.substring(start, strLength));
                    break;
                }
            }
        }
    }

    public static final void v(String log) {
        v(TAG, log);
    }

    public static final void v(String tagName, String msg) {
        if (TextUtils.isEmpty(msg))
            return;
        if (DEBUG) {
            int strLength = msg.length();
            int start = 0;
            int end = LOG_MAXLENGTH;
            for (int i = 0; i < 100; i++) {
                if (strLength > end) {
                    Log.v(tagName + i, msg.substring(start, end));
                    start = end;
                    end = end + LOG_MAXLENGTH;
                } else {
                    Log.v(tagName + i, msg.substring(start, strLength));
                    break;
                }
            }
        }
    }

    public static final void w(String log) {
        w(TAG, log);
    }

    public static final void w(String tagName, String msg) {
        if (TextUtils.isEmpty(msg))
            return;
        if (DEBUG) {
            int strLength = msg.length();
            int start = 0;
            int end = LOG_MAXLENGTH;
            for (int i = 0; i < 100; i++) {
                if (strLength > end) {
                    Log.w(tagName + i, msg.substring(start, end));
                    start = end;
                    end = end + LOG_MAXLENGTH;
                } else {
                    Log.w(tagName + i, msg.substring(start, strLength));
                    break;
                }
            }
        }
    }
}
